<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    XMLHttpRequest
    <script>
      function log() {
        let xhr = new XMLHttpRequest();
        xhr.open("post", "http://127.0.0.1:3000/report/xhr", true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send("xhr=1");
      }

      function sendBeacon() {
        const data = new FormData();
        data.append("sendB", 2);
        navigator.sendBeacon("http://127.0.0.1:3000/report/bean", data);
      }

      window.addEventListener("unload", function (event) {
        sendBeacon();
      });

      window.addEventListener("unload", function (event) {
        log();
      });
    </script>
  </body>
</html>
